package com.yedean.factory.context;

import com.yedean.factory.BeansException;
import com.yedean.factory.config.BeanPostProcessor;

/**
 * ApplicationContextAwareProcessor
 *
 * @author yedean
 * @date 2022/7/11
 */
public class ApplicationContextAwareProcessor implements BeanPostProcessor {
    
    private ApplicationContext applicationContext;

    public ApplicationContextAwareProcessor(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof ApplicationContextAware){
           ((ApplicationContextAware) bean).setApplicationContext(this.applicationContext);
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
